<?php
ob_start();
include"opensession.php";

/*
Plugin Name: Enterprise Social Aggregator
Plugin URI:   https://www.facebook.com/pages/Intersocial/203168783099892?ref=ts
Description: Widgets for your WordPress blog. An integrate service offered by the project Intersocial called "Enterpise Social Aggregator." An aggregator of the most important social network services with in addition components for Cross Posting and Social Network Analysis on the contents. Discover the new potentials of the ESA service.
Version: 1.0
Author: Alessio Tedeschi & Antonio Loiacono
License: GPL 2.0
Author URI: https://www.facebook.com/alessiotedeschi87
*/


//classe Widget
class esaclient_widget extends WP_Widget{


      public function __construct(){

	     parent::WP_Widget( 'esaclient_widget', 'Enterprise Social Aggregator', array('description' => 'Enterprise Social Aggregator Widget for your blog'));

      }
      
	public function form( $instance ){
        /* Impostazioni di default del widget */
		?>
		 <p>
		    <label>ENTERPRISE SOCIAL AGGREGATOR</label>
		 </p>
		 <?php
    	}

	
	public function widget( $args, $instance ){

        extract( $args );

        $title = apply_filters('widget_title', 'ESA' );

        echo $before_widget;
        echo $before_title . $title . $after_title;  
        
        
        if(!isset($_SESSION['page'])){
            
            
        ?>
                 
 
     
     <script>placeholderIE9();</script>        
     <div id="total" class="total">
         <div id="box"> 
             
             
                 
             <div id="serverstatus" class="serverstatus " ><script>var link='esa/server_test.php'; ovv_serverstatus(link);</script> </div>
             
             <div id="mainother" class="mainother">
             <div id="maincontent" class="maincontent">
                <h1 id="h1label">Login account</h1>
                    
                    <div class="evidence">   
                             <label for="email" class="hidden" >*Email</label>
                             <input  placeholder="*Email"  type="text" id="email" name="email" title="Insert your Email" value=""  />     
                             <br />
                             <label id="em" class="red"></label>
                    </div> 
              
                    <div class="evidence">   
                             <label for="password" class="hidden" >Password</label>
                             <input placeholder="Password"  type="password"  id="password" name="password" title="Insert your Password" value=""  />    
                             <br />
                             <label id="pa" class="red"></label>
                    </div>
                                          
                 
                    <div class="load">
                             <div class="loading fl"> <img id="imgloading" class="hidden" src="esa/img/loading.gif" /></div>
                             <div class="login "> <input type="button"  onclick="if(checklogin()){ send_data_login(); }" class="" title="Login" value="Login" name="send" id="send" /> </div>
                    </div>             
                             <div class="clear"></div>
                   
          
                 <div class="spacer"></div>
                 <div><a id="continue" class="continue"><label id="register" onclick="var link='esa/registration.php'; ovv_mainother(link); " title="New Enterprise Social Aggregator Account" > Register new account</label> </a></div>
                 
             </div>
             
             
             
             <div id="othercontent" class="othercontent"></div>
             </div>
             
             
         
         </div>
     </div> 
     
     <?php
     if($_SESSION['button']==true){
     ?>
     <script>EnableButton();</script>
     <?php
     }else{
     ?>
     <script>DisableButton();</script>
     <?php
     }
     ?>
     <script> refreshDivServerStatus();</script> 
     
    
         
         <?php
         
        }else{
          
          
            ?>
                 <div id="total" class="total">
                     <div id="box">
                         
                         <div id="serverstatus" class="serverstatus" ><script>var link='esa/server_test.php'; ovv_serverstatus(link);</script> </div>
                         <div id="mainother" class="mainother">
                         <div id="maincontent" class="maincontent"></div> 
                         <script>ovv_maincontent('<?php echo$_SESSION['page']; ?>');</script>
                         </div>  
                         
                     </div>
                 </div> 
                 <?php
                 if($_SESSION['button']==true){
                 ?>
                 <script>EnableButton();</script>
                 <?php
                 }else{
                 ?>
                 <script>DisableButton();</script>
                 <?php
                 }
                 ?>
                 <script> refreshDivServerStatus(); updatePostsDB();</script>
                 
       <?php }
        echo $after_widget;
	}
}
 
function esaclient_widgets(){
    
	register_widget( 'esaclient_widget' );
}



add_action( 'widgets_init', 'esaclient_widgets' );

 
 //scritp jquery
 wp_enqueue_script('jquery');
 
 //varius script
 wp_register_script( 'script', '/esa/script/script.js');
 wp_enqueue_script( 'script' );
 
  //varius script
 wp_register_script( 'labelify', '/esa/script/labelify.js');
 wp_enqueue_script( 'labelify' );
 
 wp_register_script( 'joptionpane1', '/esa/script/jquery.mousewheel.js');
 wp_enqueue_script( 'joptionpane1' );
 
 wp_register_script( 'joptionpane2', '/esa/script/jquery.jscrollpane.min.js');
 wp_enqueue_script( 'joptionpane2' );
 
 wp_register_script( 'scroll', '/esa/script/scrollpagination.js');
 wp_enqueue_script( 'scroll' );
 
 wp_register_script( 'shadowbox', '/esa/script/shadowbox.js');
 wp_enqueue_script( 'shadowbox' );
 
 
 
 
 
 
 //styleesheet
 wp_enqueue_style('ESAstyle', '/esa/css/style.css');
 
 //scrollbar stylesheet
 wp_enqueue_style('Joptionpanestyle', '/esa/css/jquery.jscrollpane.css');
 
 //scrollbar stylesheet
 wp_enqueue_style('JoptionpanestyleLozenge', '/esa/css/jquery.jscrollpane.lozenge.css');
 
 //scrollbar stylesheet
 wp_enqueue_style('shadowbox', '/esa/css/shadowbox-3.0.3/shadowbox.css');
 
 

 //option page 
function esa_setting_page(){
    
     //settings_fields('esa_options_group');
     try{
        $file=fopen("../esa/setting.txt","r") or exit ("do not open setting file!");
        $fileFB=fopen("../esa/facebook.txt","r") or exit ("do not open setting file!");
        $fileTW=fopen("../esa/twitter.txt","r") or exit ("do not open setting file!");
        $fileGO=fopen("../esa/google.txt","r") or exit ("do not open setting file!");
     }catch(Exception $e){
        
        echo"Write error";
        
    }
   
    
    
     $leggi=@fread($file,filesize("../esa/setting.txt"));
     $dynamic_url=nl2br($leggi);
     
     $leggiFB=@fread($fileFB,filesize("../esa/facebook.txt"));  
     $dynamic_urlFB=nl2br($leggiFB);
     
     $leggiTW=@fread($fileTW,filesize("../esa/twitter.txt"));  
     $dynamic_urlTW=nl2br($leggiTW);//aggiungere split
     if($dynamic_urlTW != null){
         $temp = explode(";",$dynamic_urlTW);
         $id_TW = $temp[0];
         $secret_TW= $temp[1];
     }else{
         //assegno valori vuoti
         $id_TW = "";
         $secret_TW= "";
     }
     $leggiGO=@fread($fileGO,filesize("../esa/google.txt"));  
     $dynamic_urlGO=nl2br($leggiGO);//aggiungere split
     if($dynamic_urlGO != null){
         $temp2 = explode(";",$dynamic_urlGO);
         $id_GO = $temp2[0];
         $secret_GO= $temp2[1];
     }else{
         //assegno valori vuoti
         $id_GO = "";
         $secret_GO= "";
     }
     
     fclose($file);
     fclose($fileFB);
     fclose($fileTW);
     fclose($fileGO);
    
    ?>
    <div id="maincontent">                       
    <h1 style="font-size:25px;color:black;font-family:Segoe UI;">Enterprise Social Aggregator Option Page<h1><br />
                
                <div style="font-size:15px;color:black;font-family:Segoe UI;">Set the ESA Url proxy server host</div>  <br /> 
                
                <div style="font-size:18px;color:black;font-family:Segoe UI;">http://
                    <input type="text"   id="proxy" name="proxy"  title="Insert proxy url" value="<?php echo$dynamic_url; ?>"  >  
         
                </div><br/>
                
                <div style="font-size:15px;color:black;font-family:Segoe UI;">Set the Facebook app parameter</div>  <br /> 
                <div style="font-size:18px;color:black;font-family:Segoe UI;">Id application: 
                    <input type="text"   id="id_appFB" name="id_appFB"  title="Insert id applicazione" value="<?php echo$dynamic_urlFB; ?>"  >                     
                </div><br/>
                
                <div style="font-size:15px;color:black;font-family:Segoe UI;">Set the Google app parameter</div>  <br /> 
                <div style="font-size:18px;color:black;font-family:Segoe UI;">Client id: 
                    <input type="text"   id="id_keyGO" name="id_keyGO"  title="Insert client id" value="<?php echo $id_GO; ?>"  >                     
                <div style="font-size:18px;color:black;font-family:Segoe UI;">Client secret: 
                    <input type="text"   id="id_secretGO" name="id_secretGO"  title="Insert client secret" value="<?php echo $secret_GO; ?>"  >                    
                </div><br/>
                
                <div style="font-size:15px;color:black;font-family:Segoe UI;">Set the Twitter app parameter</div>  <br /> 
                <div style="font-size:18px;color:black;font-family:Segoe UI;">Consumer key: 
                    <input type="text"   id="id_keyTW" name="id_keyTW"  title="Insert consumer key" value="<?php echo $id_TW; ?>"  >                     
                <div style="font-size:18px;color:black;font-family:Segoe UI;">Consumer secret: 
                    <input type="text"   id="id_secretTW" name="id_secretTW"  title="Insert consumer secret" value="<?php echo $secret_TW; ?>"  >                     
                </div><br/>
                <input type="button" onclick="send_data_option_page();" class="button-primary" id="submit" name="submit" title="Apply Changes" value="Apply Changes"/>
                <br /><br /><div style="display:inline;" id="result" class="result"></div>
                <label id="message" class="green"></label>
    </div>
            
            
           
    </div>      
    <?php
    
}

function esa_add_option_page()
{
    add_options_page('ESA Setting', 'ESA Option Menu', 'administrator', 'esa-options-page', 'esa_setting_page');
}

add_action('admin_menu', 'esa_add_option_page');


 ?>
